using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.AI;

public class MainState : ISceneState
{
    Image bg;
    GameObject loading;
    GameObject obj;//加载中的背景
    Scrollbar sc;//加载中的进度条
    bool isok=false;
    public MainState(SceneMgr sceneMgr) : base(sceneMgr)
    {
        this.SceneName = "Main";
    }
    public override void StateBegin()
    {
        bg = UITool.GetUIComponent<Image>("BG");
        loading = UITool.FindUIGameObject("loading");
        obj=UITool.FindUIGameObject("obj");
        sc=UITool.GetUIComponent<Scrollbar>("Scrollbar");
    }
    float timer = 0;
    float z = 0;
    float scTimer=0;
    public override void UpDateScene()
    {
        z += 1f;
        bg.transform.eulerAngles = new Vector3(bg.transform.eulerAngles.x, bg.transform.eulerAngles.y, z);
        timer += Time.deltaTime;
        if (timer >= 2)
        {
            loading.transform.localPosition=new Vector2(835,0);
            isok=true;
        }

        if(isok)
        {
            //设置位置到场景中间
            obj.transform.localPosition=new Vector2(0,25.5f);
            scTimer+=Time.deltaTime;
            if(scTimer>=0.5f)
            {
                sc.size+=0.1f;
                scTimer=0;
            }
        }
        if (sc.size >= 1)
        {
            //跳转场景  进入游戏界面
            m_SceneMgr.SetScene(new PrepareState(m_SceneMgr), "Prepare");
        }
    }
    public override void StateEnd()
    {

    }
}